import numpy as np
import pandas as pd


input_example = [[float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan')],
 [float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan')],
 [float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan')],
 [float('nan'), float('nan'), float('nan'), float('nan'), float('nan'), float('nan')]]



output_example = [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]


def compare(o_e, o):
    assert isinstance(o_e, np.ndarray)
    assert isinstance(o, np.ndarray)
    if o_e.shape == o.shape:

        temp = o_e == o
        flag = True
        for row in temp:
            for col in row:
                flag = flag & col
        return flag
    else:
        return False

def ourpreprocess(temp_arr):
    no=temp_arr.shape[1]
    DSIZE=temp_arr.shape[0]
    for num in range(0,no):
        value=temp_arr[:,num]
        npArray=missing_value(value,DSIZE)
        temp_arr[:, num]=npArray
    return temp_arr


def missing_value(npArray, DSISE):
    missingValue = pd.notna(npArray)
    print(missingValue)

    # 存在缺失值，进行缺失值填充
    if (pd.isna(npArray).sum() > 0):
        npArray[np.isnan(npArray)] = 0.0

    return npArray


# 用例目的
print("该用例目的为：")
print("进行缺失值处理组件功能测试，在输入错误数据状态下能否反馈")

# 子用例编号
print("子用例编号：")
print("missing_value_5")

print("****************************")
print("当前输入为：")
# 输出用例设置
print(input_example)
# 输出用例设置

print("")

print("****************************")
print("当前输出为:")
# 输出处理后数据

output = ourpreprocess(np.array(input_example))
print(output)
# 输出处理后数据

print("****************************")
print("是否正确:")
# 输出对比结果
# 需要写一个compare函数
if compare(np.array(output_example), output):
    print("输出与预定目标相符")
else:
    print("格式错误")
# 输出对比结果
print("\n")

